const { request, response } = require('express');
const express=require('express');
const {singers}=require('./singers.json');
const app=express();
app.all('/singer/:id.html',(req,res)=>{
   
    let id=req.params.id;
   
    let result =singers.find(item=>{
    if(item.id===Number(id))
    {
        return true;
    }
    });
    if(!result)
    {
        res.statusCode=404;
        res.end('<h1>404 NOT FOUND</h1>');
    }
     res.end(`<!DOCTYPE html>
     <html lang="en">
     <head>
         <meta charset="UTF-8">
         <meta http-equiv="X-UA-Compatible" content="IE=edge">
         <meta name="viewport" content="width=device-width, initial-scale=1.0">
         <title>Document</title>
     </head>
     <body>
        <h2>${result.singer_name}</h2>
        <img src="${result.singer_pic}">
     </body>
     </html>`);

});



app.listen(8000,()=>{
    console.log('服务启动成功');
})